// LAB_BPA.cpp: implementation of the CLAB_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/LAB_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CLAB_BPA::CLAB_BPA()
{
	m_chType = 'L';
	m_chSubType = 'A';
	m_chChangeCode = ' ';
	memset(m_strName,' ',8);
	m_strName[8] = '\0';
	m_dkV = 0;
	memset(m_strZone,' ',2);
	m_strZone[2] = '\0';
	memset(m_strArea,' ',10);
	m_strArea[10] = '\0';
	m_dPi = 0;
	m_dQi = 0;
	m_dPc = 0;
	m_dQc = 0;
	m_dPp = 0;
	m_dQp = 0;
	m_dPf = 0;
	m_dQf = 0;
	m_dLdp = 0;
	m_dLdq = 0;

	m_strCardType[0] = 'L';
	m_strCardType[1] = '*';
}

CLAB_BPA::CLAB_BPA(CLAB_BPA &labBPA):CCard_BPA(labBPA)
{
	m_chType = labBPA.m_chType;
	m_chSubType = labBPA.m_chSubType;
	m_chChangeCode = labBPA.m_chChangeCode;

	strcpy(m_strName,labBPA.m_strName);
	m_dkV = labBPA.m_dkV;
	strcpy(m_strZone,labBPA.m_strZone);
	strcpy(m_strArea,labBPA.m_strArea);

	m_dPi = labBPA.m_dPi;
	m_dQi = labBPA.m_dQi;
	m_dPc = labBPA.m_dPc;
	m_dQc = labBPA.m_dQc;
	m_dPp = labBPA.m_dPp;
	m_dQp = labBPA.m_dQp;
	m_dPf = labBPA.m_dPf;
	m_dQf = labBPA.m_dQf;
	m_dLdp = labBPA.m_dLdp;
	m_dLdq = labBPA.m_dLdq;
}

CLAB_BPA::~CLAB_BPA()
{

}

bool CLAB_BPA::Equals(CListItem *pItem)
{
	return true;
}

void CLAB_BPA::OutputToScreen()
{
	char strAddition[10];
	memset(strAddition,'\0',10);
	switch(m_nCardState)
	{
	case Added:
		strcpy(strAddition,"Added");
		break;
	case Deleted:
		strcpy(strAddition,"Deleted");
		break;
	case Modified:
		strcpy(strAddition,"Modified");
		break;
	case Unchanged:
		strcpy(strAddition,"Unchanged");
		break;
	default:
		break;
	}
	printf("%s Card %s: %s & %f, %s, %s;\n",strAddition,m_strCardType, \
			m_strName,m_dkV,m_strZone,m_strArea);
}

bool CLAB_BPA::UpdateEx(char *buffer)
{
	buffer[0] = m_chType;
	buffer[1] = m_chSubType;
	buffer[2] = m_chChangeCode;

	strcpy(&buffer[3],m_strName);
	DoubleToStr(m_dkV,&buffer[11],4);
	strcpy(&buffer[15],m_strZone);
	strcpy(&buffer[17],m_strArea);
	DoubleToStr(m_dPi,&buffer[27],5,3);
	DoubleToStr(m_dQi,&buffer[32],5,3);
	DoubleToStr(m_dPc,&buffer[37],5,3);
	DoubleToStr(m_dQc,&buffer[42],5,3);
	DoubleToStr(m_dPp,&buffer[47],5,3);
	DoubleToStr(m_dQp,&buffer[52],5,3);
	DoubleToStr(m_dPf,&buffer[57],5,3);
	DoubleToStr(m_dQf,&buffer[62],5,3);
	DoubleToStr(m_dLdp,&buffer[67],5,3);
	DoubleToStr(m_dLdq,&buffer[72],5,3);

	return true;
}

bool CLAB_BPA::FillEx(char *buffer)
{
	int i;

	if(EndOfSec(&buffer[0],1))
	{
		printf("Error in (CLAB_BPA: FillEx): no type!\n");
		return false;
	}
	m_chType = buffer[0];
	
	if(EndOfSec(&buffer[1],1))
	{
		printf("Error in (CLAB_BPA: FillEx): no subtype!\n");
		return false;
	}
	m_chSubType = buffer[1];

	if(EndOfSec(&buffer[2],1))
	{
		printf("Error in (CLAB_BPA: FillEx): no change code!\n");
		return false;
	}
	m_chChangeCode = buffer[2];

	for(i=0;i<8;i++)
	{
		if(!buffer[3+i])
			break;
		else
			m_strName[i] = buffer[3+i];
	}
	m_strName[i] = '\0';
	if(i!=8)
	{
		printf("Error in (CLAB_BPA: FillEx): no bus name!\n");
		return false;
	}

	m_dkV = StrToDouble(&buffer[11],4);
	if(EndOfSec(&buffer[11],4))
		return true;

	for(i=0;i<2;i++)
	{
		if(!buffer[15+i])
			break;
		else
			m_strZone[i] = buffer[15+i];
	}
	m_strZone[2] = '\0';
	if(i!=2)
		return true;

	for(i=0;i<10;i++)
	{
		if(!buffer[17+i])
			break;
		else
			m_strArea[i] = buffer[17+i];
	}
	m_strArea[10] = '\0';
	if(i!=10)
		return true;

	m_dPi = StrToDouble(&buffer[27],5,3);
	if(EndOfSec(&buffer[27],5))
		return true;

	m_dQi = StrToDouble(&buffer[32],5,3);
	if(EndOfSec(&buffer[32],5))
		return true;

	m_dPc = StrToDouble(&buffer[37],5,3);
	if(EndOfSec(&buffer[37],5))
		return true;

	m_dQc = StrToDouble(&buffer[42],5,3);
	if(EndOfSec(&buffer[42],5))
		return true;

	m_dPp = StrToDouble(&buffer[47],5,3);
	if(EndOfSec(&buffer[47],5))
		return true;

	m_dQp = StrToDouble(&buffer[52],5,3);
	if(EndOfSec(&buffer[52],5))
		return true;

	m_dPf = StrToDouble(&buffer[57],5,3);
	if(EndOfSec(&buffer[57],5))
		return true;

	m_dQf = StrToDouble(&buffer[62],5,3);
	if(EndOfSec(&buffer[62],5))
		return true;

	m_dLdp = StrToDouble(&buffer[67],5,3);
	if(EndOfSec(&buffer[67],5))
		return true;

	m_dLdq = StrToDouble(&buffer[72],5,3);
	if(EndOfSec(&buffer[72],5))
		return true;

	return true;
}
